//  this library.
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hktk_app/ienum/my/rank_type_enum.dart';
import 'package:hktk_app/ienum/subject/collection_type_enum.dart';
import 'package:hktk_app/model/my/chaper_tree_model.dart';
import 'package:hktk_app/pages/question/collection_question_page.dart';
import 'package:hktk_app/util/font_util.dart';

import 'package:hktk_app/util/view_util.dart';

/// 真题对应的item
class ViewPaperWidget extends StatelessWidget {
  /// 对应的数据
  final ChapterTreeModel paper;

  /// 对应状态
  final RankTypeEnum rankType;

  const ViewPaperWidget({
    super.key,
    required this.paper,
    required this.rankType,
  });

  /// 左边标题显示方法
  get _leftShow => Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
      Text(
        paper.name!,
        style: FontUtil.fontBlack1(28, fontWeight: FontWeight.w500),
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
      ),
      _bottomTips,
    ],
  );

  /// 底部提示
  get _bottomTips => Row(
    children: [
      _leftTips,
      hiSpace(width: 19),
      _line,
      hiSpace(width: 19),
      _qNum(),
    ],
  );

  /// 左边历年真题提示
  get _leftTips => Text(
    paper.paperType!.desc,
    style: FontUtil.fontGrey2(24),
  );

  /// 竖线分割
  get _line => Container(
    height: 22,
    decoration: BoxDecoration(
      border: Border(
        right: BorderSide(color: colorGrey5, width: 2),
      ),
    ),
  );

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        _onTapFun(context);
      },
      child: SizedBox(
        height: 82,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(child: _leftShow),
            hiSpace(width: 30),
            _rightButton(),
          ],
        ),
      ),
    );
  }

  /// 右边按钮显示
  _rightButton() {
    return SvgPicture.asset(
      "images/my/wrong_question_icon.svg",
      width: 8,
      height: 16,
    );
  }

  /// 显示数据
  _qNum() {
    int? num = paper.ec;
    String tips = "错题数";
    if (rankType == RankTypeEnum.collect) {
      num = paper.cc;
      tips = "收藏数";
    }
    return Text(
      "$tips ${num ?? 0}",
      style: FontUtil.fontGrey2(24),
    );
  }

  /// 做题点击方法
  void _onTapFun(BuildContext context) {

    Navigator.pushNamed(context, "/collection",arguments: {
      "collectId": paper.id!,
      "collectionType": CollectionTypeEnum.paper,
      "type": rankType,
    });

  }
}
